	<?php
	if(isset($_POST["submit"]))
	{
	 foreach($_POST["qty"] as $key=>$value)
	 {
	  if( ($value == 0) and (is_numeric($value)))
	  {
	   unset ($_SESSION["cart"][$key]);
	  }
	  elseif(($value > 0) and (is_numeric($value)))
	  {
	   $_SESSION["cart"][$key]=$value;
	  }
	 }
	 header("location:cart.php");
	}
?>
<html>
	<head>
 <title>Demo Shopping Cart - Created By My Kenny</title>
	 <link rel="stylesheet" href="style.css" />
	  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	 	<style>
	body{
	font:12px verdana;
	}
	.pro{
	border:1px solid #999999;
	margin:5px;
	padding:5px;
	width:400px;
	}
	a{
	color:#666666;
	text-decoration:none;
font-weight:900;
	}
	#cart{
	border:1px solid #999999;
	margin:5px;
padding:5px;
	width:400px;
	text-align:center;
	}
	</style>
	</head>
	<body>
	<h1>GIỎ HÀNG</h1>
	<?
	
	$ok=1;
	if(isset($_SESSION["cart"]))
	{
	 foreach($_SESSION["cart"] as $k => $v)
	 {
  if(isset($k))
	  {
	   $ok=2;
	  }
	 }
	}
	if($ok == 2)
	
	
	{
	   echo "<form action=cart.php method=post>";
	   foreach($_SESSION["cart"] as $key=>$value)
	   {
	    $item[]=$key;
	   }
	   $str=implode(",",$item);
   $connect=mysql_connect("localhost","root","") or die("KHÔNG KẾT NỐI VỚI CSDL");
	   mysql_select_db("linhkienmt",$connect);
	   session_start();
	   $sql="select * from sp where masp in ($str)";
	   $query=mysql_query($sql);
	   while($row=mysql_fetch_array($query))
	   {
	   echo "<div class=pro>";
	   echo "<h3>$row["tensp"]</h3>";
	   echo "Tên sản phẩm: $row["tensp"] - Gia: ".number_format($row["dongia"],3)." VND<br />";
	   echo "<p align=right>So Luong: <input type=text name=qty[$row["masp"]] size=5 value={$_SESSION['cart'][$row["masp"]]}> - ";
	   echo "<a href=delcart.php?productid=$row["masp"]>Xoa SP Nay</a></p>";
	   echo "<p align=right> Gia tien cho mon hang: ". number_format($_SESSION["cart"][$row["masp"]]*$row["dongia"],3) ."VND</p>";
	   echo "</div>";
	   $total+=$_SESSION["cart'][$row['masp"]]*$row["dongia"];
	   }
	  echo "<div class=pro align=right>";
	  echo "<b>Tong tien cho cac mon hang: <font color=red>". number_format($total,3)." VND</font></b>";
	  echo "</div>";
	  echo "<input type='submit' name='submit' value='Cap Nhat Gio Hang'>";
	  echo "<div class=pro align=center>";
	  echo "<b><a href='giohang.php'>TiepTục Mua</a> - <a href='delcart.php?productid=0'>Xoa Bo Gio Hang</a></b>";
      echo "</div>";
	  }
	 else
	 {
	  echo "<div class=pro>";
      echo '<p align=center>Ban khong co mon hang nao trong gio hang<br /><a href=giohang.php>Mua sản phẩm</a></p>';
      echo "</div>";
	 }
	?>
	
	</body>
	</html>
	